/*
	join方法，拥塞当前线程，等待所指线程完成   
 */

#include<stdlib.h>
#include<stdio.h>

#include<iostream>
#include<utility>
#include<thread>
#include<chrono>
#include<functional>
#include<atomic>

void thread_task(int n)
{
	std::this_thread::sleep_for(std::chrono::seconds(n));
	std::cout<<"hello thread "
		<<std::this_thread::get_id()
		<<"paused "<<n<<" seconds"<<std::endl;
}

int main(int argc, char **argv)
{
	std::thread threads[5];
	std::cout<<"Spawing 5 threads...\n";
	for(int i = 0; i < 5; i++)
	{
		threads[i] = std::thread(thread_task, i + 1);
	}
	std::cout<<"Done spawing threads! Now wait for threm to join\n";
	for(auto &t : threads)
	{
		t.join();	
	}
	std::cout<<"All threads joined.\n";

	return EXIT_SUCCESS;
}
